<!DOCTYPE html>
<html>
{include file="public/header" /}
<body>


<div class="layui-fluid" id="app">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">

            <div class="layui-card">
                <!--<div class="layui-card-header">按钮主题</div>-->
                <div class="layui-card-body">


                    <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                        <ul class="layui-tab-title">
                            <li class="layui-this">设置权限</li>
                        </ul>
                        <div class="layui-tab-content" style="padding-left: 0px;padding-right: 0px">

                            <div class="layui-tab-item layui-show">


                                <div class="layui-col-md12">
                                    <form class="layui-form " action="" method="post">


                                        <div class="layui-form-item"
                                             style="text-align: center;padding: 30px;margin-bottom: 0px">

                                            <div class="layui-inline">

                                                <div class="layui-input-inline" style="width: 300px;">
                                                    <input type="text" id="keyword" placeholder="输入手机号或姓名"
                                                           autocomplete="off" class="layui-input">
                                                </div>
                                                <div class="layui-form-mid" style="padding: 0px !important;">
                                                    <div class="layui-btn " id="so_base">查询</div>
                                                </div>

                                            </div>

                                        </div>

                                    </form>
                                </div>


                                <div class="layui-row layui-col-space15">


                                    <div class="layui-container"
                                         style="min-height: 550px;height: 600px;overflow: auto;margin-bottom: 30px;">


                                        <div class="layui-row" v-for="(item,index) in items" style="padding: 10px">

                                            <form class="layui-form auth_form" action="" method="post">

                                                <input type="hidden" name="id" :value="item.id">

                                                <div class="layui-col-md3" style="text-align: center">
                                                    <img :src="item.avatar"
                                                         class="layui-circle2">
                                                </div>
                                                <div class="layui-col-md8" style="line-height: 50px">
                                                    <input type="checkbox" name="role[is_pm]" value="1" title="项目经理"
                                                           :checked="item.is_pm2"
                                                           lay-skin="primary">
                                                    <input type="checkbox" name="role[is_qc]" value="1" title="质检"
                                                           :checked="item.is_qc2"
                                                           lay-skin="primary">
                                                    <input type="checkbox" name="role[is_ds]" value="1" title="设计师"
                                                           :checked="item.is_ds2"
                                                           lay-skin="primary">
                                                    <input type="checkbox" name="role[is_am]" value="1" title="客户经理"
                                                           :checked="item.is_am2"
                                                           lay-skin="primary">
                                                </div>

                                                <div class="layui-col-md1" style="text-align: center">
                                                    <button class="layui-btn layui-btn-sm" :data_index="index"
                                                            type="button" onclick="sure(this)">保存
                                                    </button>
                                                </div>

                                            </form>


                                        </div>
                                    </div>


                                </div>

                                <!--<div class="layui-col-md12 " style="text-align: center;margin-bottom: 20px">-->
                                <!--<button class="layui-btn " onclick="sure()"-->
                                <!--style="margin: 10px;padding-left: 30px;padding-right: 30px">-->
                                <!--确认-->
                                <!--</button>-->
                                <!--<button class="layui-btn layui-bg-gray"-->
                                <!--style="margin: 10px;padding-left: 30px;padding-right: 30px">-->
                                <!--取消-->
                                <!--</button>-->
                                <!--</div>-->


                            </div>


                        </div>


                    </div>
                </div>


            </div>
        </div>


    </div>


</div>
</div>


<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script>
    //vue对象
    var app = new Vue({
        el: '#app',
        data: {
            check: [],
            curr: 1,//当前页
            limit: 10,//当前页
            items: []
        }
    });


    //查找
    function so_phone() {
        var phone = $('#keyword').val();
        if (phone) {
            $.get('base_so', {keyword: phone}, function (res) {
                if (res.code == 1) {
                    app.items = res.data;
                }
            })
        }

    }


    function sure(that) {

        var index = $(that).attr('data_index');
        var form_a = $(that).parents('.auth_form');
//        console.log(form_a.serialize());
        $.post('user_auth', form_a.serialize(), function (res) {
            console.log(res);
            if (res.code == 1) {

                layer.msg(res.msg,{icon:1,time:1000});

                app.items[index].is_pm2 = res.data.is_pm2;
                app.items[index].is_qc2 = res.data.is_qc2;
                app.items[index].is_ds2 = res.data.is_ds2;
                app.items[index].is_am2 = res.data.is_am2;


            }else {
                layer.msg(res.msg,{icon:2});
            }
        });


    }


    layui.use(['form', 'layer'], function () {
        var $ = layui.$
            , layer = layui.layer
            , form = layui.form;


        $('#so_base').click(function () {
            var phone = $('#keyword').val();
            if (phone) {
                layer.load(2);
                $.get('base_so', {keyword: phone}, function (res) {
                    layer.closeAll();
                    if (res.code == 1) {
                        app.items = res.data;
                        setTimeout(function () {
                            form.render();
                        }, 500);
                    }
                })
            }
        });


        form.on('submit(select)', function (data) {
            if (!data.field.keyword) {
                return false;
            }

            layer.load(2);
            $.get("{:url('select_good')}", {keyword: data.field.keyword},
                function (res) {

                }
            );

            return false;
        });

    });


</script>


</body>
</html>




